﻿using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;

namespace Cpjit.SunnyPaine.Toolkit.Net.Generic
{
    public class IPAddressUtil
    {
        /// <summary>
        /// 获取IPv4地址。
        /// </summary>
        /// <returns></returns>
        public static List<string> GetIPv4s()
        {
            List<string> list = new List<string>();
            string hostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostEntry(hostName);
            foreach (IPAddress item in ipEntry.AddressList)
            {
                if (item.AddressFamily == AddressFamily.InterNetwork)
                {
                    list.Add(item.ToString());
                }
            }
            return list;
        }
    }
}
